package com.mz.controller;

import com.mz.common.dto.R;
import com.mz.entity.OmsGoodsCart;
import com.mz.entity.vo.CartSelectedVo;
import com.mz.entity.vo.GoodsToCartVo;
import com.mz.service.OmsGoodsCartService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * (OmsGoodsCart)表控制层
 *
 * @author makejava
 * @since 2023-12-13 13:30:29
 */
@RestController
@RequestMapping("/omsGoodsCart")
public class OmsGoodsCartController  {
    /**
     * 服务对象
     */
    @Resource
    private OmsGoodsCartService omsGoodsCartService;

    /**
     * 分页查询所有数据
     * @return 所有数据
     */
    @GetMapping("/pagination")
    public R getCartList( Long userId ) throws Exception {
        userId = 1L;
        List<OmsGoodsCart> list = omsGoodsCartService.getCartList( userId );
        return R.ok(list);
    }

    @GetMapping("/getSelectedCart")
    public R getSelectedCart( Long userId ) throws Exception {
        userId = 1L;
        List<OmsGoodsCart> list = omsGoodsCartService.getSelectedCart( userId );
        return R.ok(list);
    }


    @GetMapping("/amount")
    public R getCartGoodsAmount( Long userId ) throws Exception {
        userId = 1L;
        Integer amount = omsGoodsCartService.getCartGoodsAmount( userId );
        return R.ok(amount);
    }

    /**
     * 新增数据
     */
    @PostMapping
    public R addCart(@RequestBody  @Valid GoodsToCartVo cartVo) throws Exception {
        cartVo.setUserId( 1L );
        omsGoodsCartService.addCart( cartVo );
        return R.ok();
    }

    /**
     * 修改数量、选中状态
     * */
    @PutMapping("/updateAmountAndStatus")
    public R updateCartAmountAndStatus(@RequestBody  @Valid List<CartSelectedVo> cartSelectedVoList) throws Exception {

        omsGoodsCartService.updateCartAmountAndStatus(cartSelectedVoList);
        return R.ok();
    }


    /**
     * 修改数据
     *
     * @param omsGoodsCart 实体对象
     * @return 修改结果
     */
    @PutMapping
    public R update(@RequestBody OmsGoodsCart omsGoodsCart) {
        return null; //successsuccess(this.omsGoodsCartService.updateById(omsGoodsCart));
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @DeleteMapping
    public R delete(@RequestParam("idList") List<Long> idList) {
        return null; //successsuccess(this.omsGoodsCartService.removeByIds(idList));
    }
}

